package com.honda.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.honda.model.User;
import com.honda.util.ResultUtils;

/***
 * 
 * 
 * @ClassName: RestfulController
 * @Description:(标准restful架构风格)
 * @author: shikong
 * @date: 2018年7月4日 下午2:31:26
 * @Copyright: 2018
 */
@Controller
@RequestMapping("/rest")
public class RestfulController extends ResultUtils {

	/**
	 * 
	 * @Title: saveUser
	 * @Description: (POST 请求)
	 * @param: @param param
	 * @param: @param req
	 * @param: @param resp
	 * @return: void
	 * @throws
	 */
	@RequestMapping(method = RequestMethod.POST)
	public void saveUser(@RequestBody String param, HttpServletRequest req,
			HttpServletResponse resp) {

		// ESB 建议业务方将 esb httphead 入库，以便出现数据丢失问题方便双方查找 begin
		String requestID = req.getHeader("RequestID");
		String sourceSystem = req.getHeader("SourceSystem");
		String targetSystem = req.getHeader("TargetSystem");
		String serviceName = req.getHeader("ServiceName");

		System.out.println("requestld:" + requestID);
		System.out.println("sourceSystem:" + sourceSystem);
		System.out.println("targetSystem:" + targetSystem);
		System.out.println("serviceName:" + serviceName);
		// end

		// 业务处理
		System.out.println(param);
		User u = new User();
		u.setId("233");
		u.setPassword("admin");
		u.setUsername("admin");
		jsonResult1(u, resp);//
	}

	/**
	 * 
	 * @Title: updateUser
	 * @Description: (PUT请求)
	 * @param: @param param
	 * @param: @param req
	 * @param: @param resp
	 * @return: void
	 * @throws
	 */
	@RequestMapping(method = RequestMethod.PUT)
	public void updateUser(@RequestBody String param, HttpServletRequest req,
			HttpServletResponse resp) {

		// ESB 建议业务方将 esb httphead 入库，以便出现数据丢失问题方便双方查找 begin
		String requestID = req.getHeader("RequestID");
		String sourceSystem = req.getHeader("SourceSystem");
		String targetSystem = req.getHeader("TargetSystem");
		String serviceName = req.getHeader("ServiceName");

		System.out.println("requestld:" + requestID);
		System.out.println("sourceSystem:" + sourceSystem);
		System.out.println("targetSystem:" + targetSystem);
		System.out.println("serviceName:" + serviceName);
		// end

		// 业务处理
		System.out.println(param);
		jsonResult1("OK", resp);//
	}

	/**
	 * 
	 * @Title: deleteUserById
	 * @Description: (DELETE请求)
	 * @param: @param id
	 * @param: @param req
	 * @param: @param resp
	 * @return: void
	 * @throws
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.DELETE)
	public void deleteUserById(@PathVariable("id") Long id,
			HttpServletRequest req, HttpServletResponse resp) {

		// ESB 建议业务方将 esb httphead 入库，以便出现数据丢失问题方便双方查找 begin
		String requestID = req.getHeader("RequestID");
		String sourceSystem = req.getHeader("SourceSystem");
		String targetSystem = req.getHeader("TargetSystem");
		String serviceName = req.getHeader("ServiceName");

		System.out.println("requestld:" + requestID);
		System.out.println("sourceSystem:" + sourceSystem);
		System.out.println("targetSystem:" + targetSystem);
		System.out.println("serviceName:" + serviceName);
		// end

		// 业务处理
		System.out.println(id);
		jsonResult1("OK", resp);//

	}

	/**
	 * 
	 * @Title: getUserById
	 * @Description: (GET请求)
	 * @param: @param id
	 * @param: @param req
	 * @param: @param resp
	 * @return: void
	 * @throws
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	public void getUserById(@PathVariable("id") Long id,
			HttpServletRequest req, HttpServletResponse resp) {

		// ESB 建议业务方将 esb httphead 入库，以便出现数据丢失问题方便双方查找 begin
		String requestID = req.getHeader("RequestID");
		String sourceSystem = req.getHeader("SourceSystem");
		String targetSystem = req.getHeader("TargetSystem");
		String serviceName = req.getHeader("ServiceName");

		System.out.println("requestld:" + requestID);
		System.out.println("sourceSystem:" + sourceSystem);
		System.out.println("targetSystem:" + targetSystem);
		System.out.println("serviceName:" + serviceName);
		// end

		// 业务处理

		System.out.println(id);
		User user = new User();
		user.setId("2111");
		user.setUsername("zhangsan");
		user.setPassword("123456");
		jsonResult1(user, resp);
	}

}
